home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / rlib / complement < prev    next >
Text File  |  1994-10-08  |  765b  |  37 lines

  1. //-------------------------------------------------------------------//
  2. //  complement
  3.  
  4. //  Syntax:    complement ( A , B )
  5.  
  6. //  Description:
  7.  
  8. //  The complement function returns a vector-set that contains the
  9. //  complement of A in B. In plain English: the elements of B that are
  10. //  not in A.
  11.  
  12. //  See Also: intersection, set, union
  13.  
  14. //-------------------------------------------------------------------//
  15.  
  16. complement = function ( A, B )
  17. {
  18.   if (A.n == 0) { return [B]; }
  19.  
  20.   if (min (size (A)) != 1) 
  21.   {
  22.     error ("complement: 1st arg must be a vector");
  23.   }
  24.  
  25.   if (min (size (B)) != 1) 
  26.   {
  27.     error ("complement: 2st arg must be a vector");
  28.   }
  29.  
  30.   a = set (A); Comp = set (B);
  31.   for (i in 1:a.n)
  32.   {
  33.     Comp = Comp[ find (a[i] != Comp) ];
  34.   }
  35.   return Comp
  36. };
  37.